<?php

/**
 * This is the model class for table "time_entries".
 *
 * The followings are the available columns in table 'time_entries':
 * @property integer $id
 * @property integer $project_id
 * @property integer $user_id
 * @property integer $issue_id
 * @property double $hours
 * @property string $comments
 * @property integer $activity_id
 * @property string $spent_on
 * @property integer $tyear
 * @property integer $tmonth
 * @property integer $tweek
 * @property string $created_on
 * @property string $updated_on
 */
class TimeEntry extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return TimeEntries the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'time_entries';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('project_id, user_id, hours, activity_id, spent_on, tyear, tmonth, tweek, created_on, updated_on', 'required'),
            array('project_id, user_id, issue_id, activity_id, tyear, tmonth, tweek', 'numerical', 'integerOnly'=>true),
            array('hours', 'numerical'),
            array('comments', 'length', 'max'=>255),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, project_id, user_id, issue_id, hours, comments, activity_id, spent_on, tyear, tmonth, tweek, created_on, updated_on', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'project_id' => 'Project',
            'user_id' => 'User',
            'issue_id' => 'Issue',
            'hours' => 'Hours',
            'comments' => 'Comments',
            'activity_id' => 'Activity',
            'spent_on' => 'Spent On',
            'tyear' => 'Tyear',
            'tmonth' => 'Tmonth',
            'tweek' => 'Tweek',
            'created_on' => 'Created On',
            'updated_on' => 'Updated On',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('project_id',$this->project_id);
        $criteria->compare('user_id',$this->user_id);
        $criteria->compare('issue_id',$this->issue_id);
        $criteria->compare('hours',$this->hours);
        $criteria->compare('comments',$this->comments,true);
        $criteria->compare('activity_id',$this->activity_id);
        $criteria->compare('spent_on',$this->spent_on,true);
        $criteria->compare('tyear',$this->tyear);
        $criteria->compare('tmonth',$this->tmonth);
        $criteria->compare('tweek',$this->tweek);
        $criteria->compare('created_on',$this->created_on,true);
        $criteria->compare('updated_on',$this->updated_on,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}